<?php
namespace control;
/*
*我的线索类
*/

class clueClass extends adIndexClass
{
	private const title       = '线索';
	private const page        = 'clue';
	private const table       = 'clue';

    /**
     * 获取默认线索池池ID
     * @return mixed
     */
    public static function defaulPoolId(){
        return query('pool',"type='线索池' and coid='".self::$coid."' and isDefault = 1")['id'];
    }

    /**
     * 字段初始化
     */
    public function fieldInit($fun): array
    {
        switch ($fun) {
            case 'cooperationSearch':
            case 'allClueSearch':
                $tr = [
                    'name'          => [
                        'name'  => "{l.clue.homeForm.name}",
                        'width' => 100,
                    ],
                    'companyName' => [
                        'name'  => "{l.clue.homeForm.companyName}",
                        'width' => 150,
                    ],
                    'tel'  => [
                        'name'  => "{l.clue.homeForm.tel}",
                        'width' => 100,
                        'sort' => 1,
                    ],
                    'landline'         => [
                        'name'  => "{l.clue.homeForm.landline}",
                        'width' => 100,
                        'sort' => 1,
                    ],
                    'workFlow'          => [
                        'name'  => "{l.clue.homeForm.workFlow}",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'pool'          => [
                        'name'  => '{l.clue.homeForm.pool}',
                        'width' => 150,
                    ],
                    'source'          => [
                        'name'  => "{l.clue.homeForm.source}",
                        'width' => 150,
                    ],
                    'staff'          => [
                        'name'  => '{l.clue.homeForm.staff}',
                        'width' => 150,
                    ],
                    'time'          => [
                        'name'  => "{l.clue.homeForm.time}",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'followRecord'          => [
                        'name'  => "{l.clue.homeForm.followRecord}",
                        'width' => 150,
                    ],
                    'lastFollowTime'          => [
                        'name'  => "{l.clue.homeForm.followTime}",
                        'width' => 150,
                        'sort' => 1,
                    ]
                ];
                break;
            default:
                $tr = [
                    'name'          => [
                        'name'  => "{l.clue.homeForm.name}",
                        'width' => 150,
                    ],
                    'companyName' => [
                        'name'  => "{l.clue.homeForm.companyName}",
                        'width' => 150,
                    ],
                    'tel'  => [
                        'name'  => "{l.clue.homeForm.tel}",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'landline'         => [
                        'name'  => "{l.clue.homeForm.landline}",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'workFlow'          => [
                        'name'  => "{l.clue.homeForm.workFlow}",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'pool'          => [
                        'name'  => '{l.clue.homeForm.pool}',
                        'width' => 150,
                    ],
                    'source'          => [
                        'name'  => "{l.clue.homeForm.source}",
                        'width' => 150,
                    ],
                    'time'          => [
                        'name'  => "{l.clue.homeForm.time}",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'followRecord'          => [
                        'name'  => "{l.clue.homeForm.followRecord}",
                        'width' => 150,
                    ],
                    'lastFollowTime'          => [
                        'name'  => "{l.clue.homeForm.followTime}",
                        'width' => 150,
                        'sort' => 1,
                    ]
                ];
        }
        return $tr;
    }

	/**
	 * 查询表单
	 *
	 * @param string $workFlow
	 * @return string
	 */
	public function homeForm(string $workFlow): string
	{
        $array = [
            [
                [
                    L('clue.homeForm.name') => text(array("name" => "name")),
                    L('clue.homeForm.companyName')   => text(array("name" => "companyName")),
                    L('clue.homeForm.tel') => text(array("name" => "tel")),
                ],
                [
                    L('clue.homeForm.landline') => text(array("name" => "landline")),
                    L('clue.homeForm.workFlow') => select(array('name' => 'workFlow', 'option' => explode('，', para('clueWorkFlow')))),
                    L('clue.homeForm.source') => select(array('name' => 'source', 'option' => explode('，', para('clueSource')))),

                ],
                [
                    L('clue.homeForm.pool')  => selectMultiple(array('table' => 'pool', 'sqlField' => 'name', 'where' => "type = '线索池' and coid = '".self::$coid."' order by list asc", 'sqlId' => 'id', 'name' => 'poolId', 'class' => 'width200')),
                    L('clue.detail.time') => text(array("name" => "time", 'laydate' => ['type' => 'date', 'range' => '~'])),
                ]
            ]
        ];
        if ($workFlow == '我协作的') {
            $array[0][2][L('clue.homeForm.staff')] = selectMultiple(array('table' => 'staff', 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'manager', 'class' => 'width200'));
        } elseif ($workFlow == '全部线索') {
            $array[0][2][L('clue.homeForm.staff')] = selectMultiple(array('table' => 'staff', 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'manager', 'class' => 'width200'));
        }
		return $this->tableShow($array,1);
	}

    /*列表页-查询条件*/
    public function homeOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->homeForm('我的线索');
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

	/**
	 * 查询条件
	 *
	 * @param string $workFlow
	 * @return string
	 */
	public function home(): string
	{
        $html = $this->homeOptions(false);
        //控件
        $button = "";
        $url = root . "control/adIndex.html?cla=" . self::page;
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('".self::page."','edit')\" class='spanButton'>" . L('clue.homeForm.new') . "</span>\n
                        <span onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'client'})\" class='spanButton'>" . L('clue.homeForm.transferClient') . "</span>\n
                        <span onclick=\"layer('" . self::page . "','mergeContact',{})\" class='spanButton'>" . L('clue.homeForm.mergeContact') . "</span>\n
                        <span onclick=\"layer('" . self::page . "','transfer',{})\" class='spanButton'>" . L('clue.homeForm.transfer') . "</span>\n
                        <span onclick=\"layer('" . self::page . "','publicClue',{})\" class='spanButton'>" . L('clue.homeForm.publicClue') . "</span>\n
                        <span onclick=\"layer('" . self::page . "','pool',{})\" class='spanButton'>" . L('clue.homeForm.poolClue') . "</span>\n
                        ";// <span onclick=\"\" class='spanButton'>发送短信</span>\n
        }
        //导入
        if ($this->power(self::page, 'import')) {
            $button .="<span class='spanButton' onclick=\"layer('importTemplate','importFrame',{cla:'".self::page."'})\">导入</span>";
        }
        if ($this->power(self::page, "export")) {
            $button .="<span class='spanButton' onclick=\"layer('importTemplate','exportFrame',{cla:'".self::page."'})\">导出</span>";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'del'})\">" . L('clue.homeForm.del') . "</span>\n";
        }
		return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
	}

	/*社保数据-列表页-查询结果*/
	public function homeSearch()
	{
		//全等查询数组
		$equal = array(
			"manager"  => self::$stid,//员工
			'workFlow' => $this->post('workFlow'),
			'source'   => $this->post('source'),
			'poolId'   => $this->post('poolId'),
            'coid'=>self::$coid
		);
		$like  = array(
			"name"        => $this->post('name'),//姓名
			"companyName" => $this->post('companyName'),
			"tel"         => $this->post('tel'),
			"landline"    => $this->post('landline'),
			"text"        => $this->post('text'),
		);
		$and   = " and isClient = 0";
		if ($this->post('time')) {
			$timeArr = explode(' ~ ', $this->post('time'));
			$and     .= " and date(time) >='{$timeArr[0]}' and date(time) <='{$timeArr[1]}'";
		}
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'time',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(),
        ));
		//获取查询结果
		$where                       = search(array("=" => $equal, 'like' => $like)) . $and;
		$page                        = $this->page(array("table" => self::table, "where" => $where, "order" => $orderBy['orderBy']));
		$_SESSION[self::page]['sql'] = $page['fullSql'];
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("listForm", "listId")
        );
		//获取记录
		$url = root . "control/adIndex.html?cla=" . self::page;
		//获取记录
		foreach ($page['array'] as $array) {
			//列表控件
			$dominate = array(
				"box"    => array("name" => "listId", "value" => $array['id']),
				"edit"   => array("title" => L('clue.homeForm.edit'), "click" => "layer('" . self::page . "','edit',{id:'" . $array['id'] . "'})"),
				"detail" => array("title" => L('clue.homeForm.detail'), "click" => "newIframe('" . L('clue.homeForm.detail') . "','" . $url . "&fun=detail&id=" . $array['id'] . "')"),
			);
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "pool":
                        $pool     = query('pool', "id = '$array[poolId]'");
                        $row[] = $pool['name'];
                        break;
                    case "followRecord":
                        $follow   = query('follow', " targetId = '$array[id]' order by time desc");
                        $row[] = $follow['text'];
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
		}
		//控件
		$button = "";
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
		//返回
		$json['html'] = $page['hint'] . $button . "<form name='listForm'>" . $li . "</form>" . $page['button'];
		return json_encode($json, 320);
	}

    /*列表页-查询条件*/
    public function cooperationOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->homeForm('我协作的');
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 我协作的
     */
    public function cooperation(): bool|string
    {
        $html = $this->cooperationOptions(false);
        $button = "";
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
    }

    public function cooperationSearch(): bool|string
    {
        //全等查询数组
        $equal = array(
            "manager"  => $this->post('manager'),//员工
            'workFlow' => $this->post('workFlow'),
            'source'   => $this->post('source'),
            'poolId'   => $this->post('poolId'),
            'coid'=>self::$coid
        );
        $like  = array(
            "name"        => $this->post('name'),//姓名
            "companyName" => $this->post('companyName'),
            "tel"         => $this->post('tel'),
            "landline"    => $this->post('landline'),
            "text"        => $this->post('text'),
        );
        $and   = " and manager !='' and isClient=0 and collaborator like '%" . self::$stid . "%'";
        if ($this->post('time')) {
            $timeArr = explode(' ~ ', $this->post('time'));
            $and     .= " and date(time) >='{$timeArr[0]}' and date(time) <='{$timeArr[1]}'";
        }
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'time',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(),
        ));
        //获取查询结果
        $where = search(array("=" => $equal, 'like' => $like)) . $and;
        $page  = $this->page(array("table" => self::table, "where" => $where, "order" => $orderBy['orderBy']));
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("recordForm", "recordId")
        );
        //获取记录
        $url = root . "control/adIndex.html?cla=" . self::page;
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                "box"    => array("name" => "listId", "value" => $array['id']),
                "detail" => array("title" => L('clue.homeForm.detail'), "click" => "newIframe('" . L('clue.homeForm.detail') . "','" . $url . "&fun=detail&id=" . $array['id'] . "')"),
            );
            $liButton[] = $this->dominate($dominate);
            $follow   = query('follow', " targetId = '$array[id]' order by time desc");
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "pool":
                        $pool     = query('pool', "id = '$array[poolId]'");
                        $row[] = $pool['name'];
                        break;
                    case "staff":
                        $row[] = self::findStaff($array['manager']);
                        break;
                    case "followRecord":
                        $row[] = $follow['text'];
                        break;
                    case "lastFollowTime":
                        $row[] = $follow['time'];
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = "";
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='cooperationForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function allClueOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->homeForm('全部线索');
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 我协作的
     */
    public function allClue(): bool|string
    {
        $html = $this->allClueOptions(false);
        //控件
        $button = "";
        $url = root . "control/adIndex.html?cla=" . self::page;
        if ($this->power('allClue', "edit")) {
            $button .= "
                        <span onclick=\"layer('" . self::page . "','transfer',{})\" class='spanButton'>" . L('clue.homeForm.transfer') . "</span>\n
                        <span onclick=\"layer('" . self::page . "','publicClue',{})\" class='spanButton'>" . L('clue.homeForm.publicClue') . "</span>\n
                        ";
        }
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
    }

    public function allClueSearch()
    {
        //自己的，协作的，直接下级的
        //全等查询数组
        $equal = array(
            "manager"  => $this->post('manager'),//员工
            'workFlow' => $this->post('workFlow'),
            'source'   => $this->post('source'),
            'poolId'   => $this->post('poolId'),
            'coid'=>self::$coid
        );
        $like  = array(
            "name"        => $this->post('name'),//姓名
            "companyName" => $this->post('companyName'),
            "tel"         => $this->post('tel'),
            "landline"    => $this->post('landline'),
            "text"        => $this->post('text'),
        );
        $and   = " and manager !='' and isClient = 0";
        if ($this->power('allClue', "seeAll")) {
            //查看所有的权限
            $and .= " and 1=1";
        } elseif ($this->power('allClue', "seeGroup")) {
            //查看本组（直接下级）
            $and .= " and (collaborator like '%" . self::$stid . "%'  or manager = '" . self::$stid . "' or manager in (select stid from staff where manager = '" . self::$stid . "'))";
        } else {
            //查看自己
            $and .= " and (collaborator like '%" . self::$stid . "%'  or manager = '" . self::$stid . "')";
        }
        if ($this->post('time')) {
            $timeArr = explode(' ~ ', $this->post('time'));
            $and     .= " and date(time) >='{$timeArr[0]}' and date(time) <='{$timeArr[1]}'";
        }
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'time',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(),
        ));
        //获取查询结果
        $where = search(array("=" => $equal, 'like' => $like)) . $and;
        $page  = $this->page(array("table" => self::table, "where" => $where, "order" => $orderBy['orderBy']));
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("allClueForm", "listId")
        );
        //获取记录
        $url = root . "control/adIndex.html?cla=" . self::page;
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                "box"    => array("name" => "listId", "value" => $array['id']),
                "detail" => array("title" => L('clue.homeForm.detail'), "click" => "newIframe('" . L('clue.homeForm.detail') . "','" . $url . "&fun=detail&id=" . $array['id'] . "')"),
            );
            $liButton[] = $this->dominate($dominate);
            $follow   = query('follow', " targetId = '$array[id]' order by time desc");
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "pool":
                        $pool     = query('pool', "id = '$array[poolId]'");
                        $row[] = $pool['name'];
                        break;
                    case "staff":
                        $row[] = self::findStaff($array['manager']);
                        break;
                    case "followRecord":
                        $row[] = $follow['text'];
                        break;
                    case "followTime":
                        $row[] = $follow['lastFollowTime'];
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = "";
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='allClueForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

	/**
	 * 转到公共线索
	 */
	public function publicClue(): bool|string
	{
		//生成表单
		$html = $this->layerEdit(array(
			"table"      => array(
				array(
					must . L('clue.publicClue.tips') . "：" => L('clue.publicClue.tipsWord'),
				),
			),
		));
		//返回
		return $this->layer(array("title" => L('clue.publicClue.publicClue'), 'winFix' => true, 'width' => 600, "height" => 200, "html" => $html, 'formTwo' => 'listForm,allClueForm'));
	}

	/**
	 *  转到公共线索编辑
	 */
	public function publicClueEdit(): bool|string
	{
		$listId = $this->post('id') ? [$this->post('id')] : $this->post('listId');
		if (!$this->power(self::page, 'edit') && !$this->power('allClue', 'edit')) {
			$json['warn'] = L('clue.publicClueEdit.power');
		} elseif (empty($listId) || !is_array($listId)) {
			$json['warn'] = L('clue.publicClueEdit.notFind');
		} else {
			$x = 0;
			foreach ($listId as $id) {
				//线索
				$info = query(self::table, " id = '$id'");
				if ($info['manager'] == self::$stid || $this->power(self::page, 'admin')) {
					$warn = update(array(
						'table' => self::table,
						'field' => [
							'manager'      => '',
							'collaborator' => '',
							'see'          => '',
						],
						'where' => "id = '$id'",
					));
					if (in_array($warn, ['新增成功', '更新成功'])) {
						$x++;
						$text = str_replace(['{{staffName}}', '{{name}}', '{{id}}'], [$this->control['name'], $info['name'], $id], L('clue.publicClueEdit.logText'));
						$this->logText(["type" => self::page, "text" => $text]);
						//日志
						$this->logWrite($id, '转到公共线索', str_replace(['{{staffName}}'], [$this->control['name']], L('clue.publicClueEdit.log')));
					}
				} else {
					$text = str_replace(['{{staffName}}', '{{name}}'], [$this->control['name'], $info['name']], L('clue.publicClueEdit.failLog'));
					$this->logText(["type" => self::page, "text" => $text]);
				}
			}
			$json['warn']     = 2;
			$_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('clue.publicClueEdit.warn'));
		}
		return json_encode($json, 320);
	}


	/**
	 * 转到线索池
	 */
	public function pool()
	{
		//生成表单
		$html = $this->layerEdit(array(
			"table"      => array(
				array(
					must . L('clue.pool.pool') . "：" => selectMultiple(array('table' => 'pool', 'where' => "type = '线索池' and coid = '".self::$coid."'", "title" => L('clue.pool.choice'), 'sqlField' => 'name', 'sqlId' => 'id', 'name' => 'poolId')),
				),
			),
		));
		//返回
		return $this->layer(array("title" => L('clue.pool.transferPool'), 'winFix' => true, "height" => 200, "html" => $html, 'formTwo' => 'listForm'));
	}

	/**
	 *  转到线索池编辑
	 */
	public function poolEdit()
	{
		$listId = $this->post('id') ? [$this->post('id')] : $this->post('listId');
		$poolId = $this->post('poolId');
		$pool   = query('pool', "id = '$poolId'");
		if (!$this->power(self::page, 'edit')) {
			$json['warn'] = L('clue.poolEdit.power');
		} elseif (empty($listId) || !is_array($listId)) {
			$json['warn'] = L('clue.poolEdit.notFindClue');
		} elseif (empty($pool['id'])) {
			$json['warn'] = L('clue.poolEdit.empty');
		} else {
			$x = 0;
			foreach ($listId as $id) {
				//线索
				$info = query(self::table, " id = '$id'");
				if ($info['manager'] == self::$stid) {
					$warn = update(array(
						'table' => self::table,
						'field' => [
							'poolId' => $pool['id'],
						],
						'where' => "id = '$id'",
					));
					if (in_array($warn, ['新增成功', '更新成功'])) {
						$x++;
						$text = str_replace(['{{staffName}}', '{{name}}', '{{id}}', '{{pool}}'], [$this->control['name'], $info['name'], $id, $pool['name']], L('clue.poolEdit.logText'));
						$this->logText(["type" => self::page, "text" => $text]);
						//日志
						$this->logWrite($id, '添加到线索池', str_replace(['{{staffName}}', '{{pool}}'], [$this->control['name'], $pool['name']], L('clue.poolEdit.log')));
					}
				} else {
					$text = str_replace(['{{staffName}}', '{{pool}}'], [$this->control['name'], $pool['name']], L('clue.poolEdit.failLog'));
					$this->logText(["type" => self::page, "text" => $text]);
				}
			}
			$json['warn']     = 2;
			$_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('clue.poolEdit.warn'));
		}
		return json_encode($json, 320);
	}

	/**
	 * 转交
	 */
	public function transfer()
	{
		//生成表单
		$html = $this->layerEdit(array(
			"table"      => array(
				array(
					must . L('clue.transfer.manager') . "：" => selectMultiple(array("title" => L('clue.transfer.choice'), 'option' => $this->staffOption(), 'name' => 'manager')),
				),
				array(
					L('clue.transfer.collaborator') . "：" => selectMultiple(array('table' => 'staff', 'multiple' => true, "title" => L('clue.transfer.choice'), 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'collaborator[]')),
				),

			)
		));
		//返回
		return $this->layer(array("title" => L('clue.transfer.transmit'), 'winFix' => true, "height" => 260, "html" => $html, 'formTwo' => 'listForm,allClueForm',));
	}

	/**
	 * 获取转交给他人的选项
	 *
	 * @return array
	 */
	public function staffOption(): array
	{
		$option = [];
		$result = find(array('table' => 'staff', 'where' => "state in ('试用','转正')"));
		foreach ($result['array'] as $array) {
			$option[$array['stid']] = $array['name'];
		}
		return $option;
	}


	/**
	 * 转交编辑
	 */
	public function transferEdit(): bool|string
	{
		$listId = $this->post('id') ? [$this->post('id')] : $this->post('listId');
		$field  = array(
			'manager'      => $this->post('manager'),
			'collaborator' => $this->post('collaborator') && is_array($this->post('collaborator')) ? implode(',', array_unique($this->post('collaborator'))) : '',
		);
		if (!$this->power(self::page, 'edit') && !$this->power('allClue', 'edit')) {
			$json['warn'] = L('clue.transferEdit.power');
		} elseif (empty($listId) || !is_array($listId)) {
			$json['warn'] = L('clue.transferEdit.notFindClue');
		} elseif (empty($this->post('manager'))) {
			$json['warn'] = L('clue.transferEdit.choiceManage');
		} elseif (is_array($this->post('collaborator')) && in_array($field['manager'], $this->post('collaborator'))) {
			$json['warn'] = L('clue.transferEdit.choiceError');
		} else {
			$x = 0;
			//查看范围
			$field['see']          = implode(',', array_unique(array_filter(array_merge([$field['manager']], explode(',', $field['collaborator'])))));
			$field['collaborator'] = empty($field['manager']) ? '' : $field['collaborator'];
			$manager               = query('staff', "stid = '$field[manager]'");
			foreach ($listId as $id) {
				$info = query(self::table, " id = '$id'");
				if ($info['manager'] != $field['manager'] && ($info['manager'] == self::$stid || $this->power(self::page, 'admin'))) {
					$warn = update(array(
						'table' => self::table,
						'field' => $field,
						'where' => " id = '$id'",
					));
					if ($warn == '更新成功') {
						$x++;
						$this->logWrite($id, '转交', str_replace(['{{staffName}}', '{{name}}', '{{manage}}'], [$this->control['name'], $info['name'], $manager['name']], L('clue.transferEdit.logText')));
						$text = str_replace(['{{staffName}}', '{{name}}', '{{id}}', '{{manage}}'], [$this->control['name'], $info['name'], $id, $manager['name']], L('clue.transferEdit.log'));
						$this->logText(["type" => self::page, "text" => $text]);
					}
				} else {
					$text = str_replace(['{{staffName}}', '{{name}}'], [$this->control['name'], $info['name']], L('clue.transferEdit.failLog'));
					$this->logText(["type" => self::page, "text" => $text]);
				}
			}
			$json['warn']     = 2;
			$_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('clue.transferEdit.warn'));
		}
		return json_encode($json, 320);
	}

	/**
	 * 转为客户
	 */
	public function client(): bool|string
	{
		$listId = $this->post('id') ? [$this->post('id')] : $this->post('listId');
		if (!$this->power(self::page, 'edit')) {
			$json['warn'] = L('clue.client.power');
		} elseif (empty($listId) || !is_array($listId)) {
			$json['warn'] = L('clue.client.notFind');
		} else {
			$x = 0;
			foreach ($listId as $id) {
				//线索
				$info = query(self::table, " id = '$id'");
                $info['companyName'] = $info['companyName']?:$info['name'];
				//查看是否有相同公司名称的客户
				$kehu = query('kehu', "companyName = '$info[companyName]'");
				if (empty($kehu['khid'])) {
					//没有此客户
					$field            = [
						'khid'         => self::getId(),
						'clueId'       => $info['id'],
						'companyName'  => $info['companyName'],
						'collaborator' => $info['collaborator'],
						'manager'      => $info['manager'],
						'see'          => $info['see'],
						'stid'         => self::$stid,
						'landline'     => $info['landline'],
						'contactName'  => $info['name'],
						'contactTel'   => $info['tel'],
						'contactQQ'    => $info['qq'],
						'contactWx'    => $info['weChat'],
						'website'      => $info['website'],
						'address'      => $info['address'],
						'source'       => $info['source'],
						'poolId'       => 'defaultClientPool',
						'email'        => $info['email'],
						'workFlow'     => $info['workFlow'],
						'followTime'   => $info['followTime'],
						'tags'         => $info['tags'],
						'text'         => $info['text'],
						'updateTime'   => $this->time,
						'time'         => $this->time,
                        'coid'=>self::$coid
					];
					$userNo           = codeTemplateClass::generateCode('client', [
						'prefix' => 'C',
						'table'  => 'kehu',
						'field'  => 'orderNo',
						'where'  => '',
					], $field);
					$field['orderNo'] = $userNo;
					$warn             = insert(array(
						'table' => 'kehu',
						'field' => $field,
					));
					if ($warn == '新增成功') {
						$x++;
						//复制对应的标签到客户中
						$all = find(array('table' => 'kehu_label', 'where' => "targetId = '$info[id]' order by list asc"));
						foreach ($all['array'] as $array) {
							insert(array(
								'table' => 'kehu_label',
								'field' => [
									'id'            => self::getId(),
									'targetId'      => $field['khid'],
									'tag_detail_id' => $array['tag_detail_id'],
									'tagId'         => $array['tagId'],
									'type'          => 1,
                                    'coid'=>self::$coid
								],
							));
						}
						//复制跟进记录到客户
						$all = find(array('table' => 'follow', 'where' => "targetId = '$info[id]' order by time asc"));
						foreach ($all['array'] as $array) {
							insert(array(
								'table' => 'follow',
								'field' => [
									'id'         => self::getId(),
                                    'coid'=>self::$coid,
									'stid'       => $array['stid'],
									'target'     => '客户',
									'targetId'   => $field['khid'],
									'targetName' => $field['companyName'],
									'followType' => $array['followType'],
									'text'       => $array['text'],
									'time'       => $array['time'],
								],
							));
						}

						$text = str_replace(['{{staffName}}', '{{name}}', '{{id}}'], [$this->control['name'], $info['name'], $id], L('clue.client.logText'));
						$this->logText(["type" => self::page, "text" => $text]);
						//日志
						$this->logWrite($id, '转为客户', str_replace(['{{staffName}}'], [$this->control['name']], L('clue.client.log')));
						//更新状态
						update(array('table' => self::table, 'field' => ['isClient' => 1], 'where' => "id = '$id'"));
					} else {
						$text = str_replace(['{{staffName}}', '{{name}}', '{{id}}'], [$this->control['name'], $info['name'], $id], L('clue.client.failLog'));
						$this->logText(["type" => self::page, "text" => $text]);
					}
				} else {
					//已有此客户则合并联系人
					$kehuStaff = query('kehu_staff', "khid = '$kehu[khid]' and tel = '$info[tel]'");
					if (empty($kehuStaff['id'])) {
						$warn = insert(array(
							'table' => 'kehu_staff',
							'field' => [
								'id'         => self::getId(),
                                'coid'=>self::$coid,
								'stid'       => $info['manager'],
								'khid'       => $kehu['khid'],
								'name'       => $info['name'],
								'tel'        => $info['tel'],
								'phone'      => $info['landline'],
								'qq'         => $info['qq'],
								'WeChat'     => $info['weChat'],
								'birthDay'   => $info['birthDay'],
								'address'    => $info['address'],
								'updateTime' => $this->time,
								'time'       => $this->time,
							],
						));
						if ($warn == '新增成功') {
							$x++;
							$text = str_replace(['{{staffName}}', '{{name}}', '{{id}}'], [$this->control['name'], $info['name'], $id], L('clue.client.mergeText'));
							$this->logText(["type" => self::page, "text" => $text]);
							//日志
							$this->logWrite($id, '转为客户', str_replace(['{{staffName}}'], [$this->control['name']], L('clue.client.log')));
							//更新状态
							update(array('table' => self::table, 'field' => ['isClient' => 1], 'where' => "id = '$id'"));
						}
					} else {
						$x++;
						//日志
						$this->logWrite($id, '转为客户', str_replace(['{{staffName}}'], [$this->control['name']], L('clue.client.log')));
						//更新状态
						update(array('table' => self::table, 'field' => ['isClient' => 1], 'where' => "id = '$id'"));
					}
				}
			}
			$json['warn']     = 2;
			$_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('clue.client.warn'));
			$json['href']     = root . 'control/adIndex.html?cla=clue&fun=home';
		}
		return json_encode($json, 320);
	}

	/**
	 * 合并联系人到客户
	 *
	 * @return bool|string
	 */
	public function mergeContact(): bool|string
	{
		//生成表单
		$html = $this->layerEdit(array(
			"table"      => array(
				array(
					must . L('clue.mergeContact.client') . "：" => selectMultiple(array('table' => 'kehu', 'where' => "coid = '".self::$coid."'", "title" => L('clue.mergeContact.choice'), 'sqlField' => 'companyName', 'sqlId' => 'khid', 'name' => 'khid')),
				),
			),
		));
		//返回
		return $this->layer(array("title" => L('clue.mergeContact.mergeContact'), 'winFix' => true, "height" => 200, "html" => $html, 'formTwo' => 'listForm'));
	}

	/**
	 * 合并联系人到客户
	 */
	public function mergeContactEdit(): bool|string
	{
		$listId = $this->post('listId');
		$khid   = $this->post('khid');
		$kehu   = query('kehu', "khid = '$khid'");
		if (!$this->power(self::page, 'edit')) {
			$json['warn'] = L('clue.mergeContactEdit.power');
		} elseif (empty($listId) || !is_array($listId)) {
			$json['warn'] = L('clue.mergeContactEdit.notFind');
		} elseif (empty($kehu['khid'])) {
			$json['warn'] = L('clue.mergeContactEdit.empty');
		} else {
			$x = 0;
			foreach ($listId as $id) {
				//线索
				$info = query(self::table, " id = '$id'");
				//已有此客户则合并联系人
				$kehuStaff = query('kehu_staff', "khid = '$kehu[khid]' and tel = '$info[tel]'");
				if (empty($kehuStaff['id'])) {
					$warn = insert(array(
						'table' => 'kehu_staff',
						'field' => [
							'id'         => self::getId(),
                            'coid'=>self::$coid,
							'stid'       => $info['manager'],
							'khid'       => $kehu['khid'],
							'name'       => $info['name'],
							'tel'        => $info['tel'],
							'phone'      => $info['landline'],
							'qq'         => $info['qq'],
							'WeChat'     => $info['weChat'],
							'updateTime' => $this->time,
							'time'       => $this->time,
						],
					));
				} else {
					$warn = update(array(
						'table' => 'kehu_staff',
						'field' => [
							'name'   => $info['name'],
							'tel'    => $info['tel'],
							'phone'  => $info['landline'],
							'qq'     => $info['qq'],
							'WeChat' => $info['weChat'],
						],
						'where' => "id = '$kehuStaff[id]'",
					));
				}
				if (in_array($warn, ['新增成功', '更新成功'])) {
					$x++;
					//将此线索视为转为客户
					update(array(
						'table' => self::table,
						'field' => [
							'isClient' => 1,
						],
						'where' => "id = '$info[id]'",
					));
					$text = str_replace(['{{staffName}}', '{{name}}', '{{id}}', '{{companyName}}'], [$this->control['name'], $info['name'], $id, $kehu['companyName']], L('clue.mergeContactEdit.logText'));
					$this->logText(["type" => self::page, "text" => $text]);
					//日志
					$this->logWrite($id, '转为客户', str_replace(['{{staffName}}', '{{companyName}}'], [$this->control['name'], $kehu['companyName']], L('clue.mergeContactEdit.log')));
				}
			}
			$json['warn']     = 2;
			$_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('clue.mergeContactEdit.warn'));
		}
		return json_encode($json, 320);
	}


	/**
	 * 编辑页
	 *
	 * @return string
	 */
    public function edit()
    {
        $info       = query(self::table, " id = '" . $this->post('id') . "' ");
        $tags       = '';
        $kehu_label = find(array('table' => 'kehu_label', 'where' => "targetId = '$info[id]' and targetId !='' order by list asc"));
        foreach ($kehu_label['array'] as $array) {
            $tag_detail = query('tag_detail', "id = '$array[tag_detail_id]'");
            $tags       .= "<span class='background-color-gray' style='margin-right: 5px'>{$tag_detail['name']}<input name='labelMxId[]' type='hidden' value='{$tag_detail['id']}'></span>";
        }
        //表单
        $html = $this->layerEdit([
            "table" => [
                [
                    must . L('clue.edit.name') . "：" => text(["name" => "name", 'class' => 'text', "value" => $info['name']]),
                    L('clue.edit.companyName') . "：" => text(["name" => "companyName", 'class' => 'text', "value" => $info['companyName']]),
                ],
                [
                    L('clue.edit.department') . "：" => text(["name" => "department", 'class' => 'text', "value" => $info['department']]),
                    L('clue.edit.job') . "："        => text(["name" => "job", 'class' => 'text', "value" => $info['job']]),
                ],
                [
                    L('clue.edit.tel') . "："      => text(["name" => "tel", 'class' => 'text', "value" => $info['tel']]),
                    L('clue.edit.landline') . "：" => text(["name" => "landline", 'class' => 'text', "value" => $info['landline']]),
                ],
                [
                    L('clue.edit.weChat') . "：" => text(["name" => "weChat", 'class' => 'text', "value" => $info['weChat']]),
                    L('clue.edit.qq') . "："     => text(["name" => "qq", 'class' => 'text', "value" => $info['qq']]),
                ],
                [
                    L('clue.edit.website') . "：" => text(["name" => "website", 'class' => 'text', "value" => $info['website']]),
                    L('clue.edit.email') . "："   => text(["name" => "email", 'class' => 'text', "value" => $info['email']]),
                ],
                [
                    L('clue.edit.address') . "：" => text(["name" => "address", 'title' => L('clue.edit.keyword'), 'class' => 'text', "value" => $info['address']]) . (componentClass::addressIco("layer('client','map',{})")) .
                        hidden(array('name' => 'location', 'value' => $info['lng'] ? ($info['lat'] . ',' . $info['lng']) : '')).
                        hidden(array('name' => 'region', 'value' => $info['region']?:'')),
                    L('clue.edit.source') . "：" => select(["name" => "source", 'class' => 'text', 'title' => L('clue.edit.choice'), 'option' => explode('，', para('clueSource')), "value" => $info['source']]),
                ],
                [
                    L('clue.edit.tags') . "："   => "<span id='tags'>{$tags}</span><span class='spanButton' style='margin:0' onclick=\"layer('client','add_label',$('form[name=clueEditForm]').serialize())\">" . L('clue.edit.addTags') . "</span>",
                ],
                [
                    L('clue.edit.workFlow') . "："   => select(["name" => "workFlow", 'class' => 'text', 'title' => L('clue.edit.choice'), 'option' => explode('，', para('clueWorkFlow')), "value" => $info['workFlow']]),
                    L('clue.edit.followTime') . "：" => text(["name" => "followTime", 'laydate' => ['type' => 'datetime'], 'class' => 'text', "value" => $info['followTime']]),
                ],
                [
                    must . L('clue.edit.manager') . "：" => selectMultiple(array('table' => 'staff', "title" => L('clue.edit.choice'), 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'manager', 'value' => $info['manager'] ?: self::$stid)),
                    L('clue.edit.collaborator') . "："   => selectMultiple(array('table' => 'staff', 'where' => " stid !='$info[manager]'", 'multiple' => true, "title" => L('clue.edit.choice'), 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'collaborator[]', 'value' => $info['collaborator'])),
                ],
                [
                    L('clue.edit.pool') . "：" => selectMultiple(array('name' => 'poolId', 'title' => L('clue.edit.choice'), 'where' => "type = '线索池' and coid = '".self::$coid."'", 'table' => 'pool', 'sqlId' => 'id', 'sqlField' => 'name', 'value' => $info['poolId'])),
                ],
                [
                    L('clue.edit.remark') . "：" => textarea(["name" => "text", 'class' => 'textarea', "value" => $info['text']]),
                ],
            ],
        ]);
        $html .= <<<efo
<script>
$(function(){
    $("input[name='address']").bigAutocomplete({
        // width:543,
        url:root + 'control/adIndex.html?cla=component&fun=getAddress',
        callback:function(data){
            $("[name='location']").val(data.location)
        }
    });
})
</script>
efo;
        //返回
        return $this->layer(array("title" => L('job.button.editor').self::title, "height" => 600, "html" => $html));
    }

	public function editEdit(): bool|string
	{
		$id         = $this->post('id') ?: self::getId();
		$labelMxId  = $this->post('labelMxId');//标签ID
		$field      = [
			'name'         => $this->post('name'),
			'companyName'  => $this->post('companyName') ?: $this->post('name'),
			'department'   => $this->post('department'),
			'job'          => $this->post('job'),
			'tel'          => $this->post('tel'),
			'landline'     => $this->post('landline'),
			'weChat'       => $this->post('weChat'),
			'qq'           => $this->post('qq'),
			'website'      => $this->post('website'),
			'email'        => $this->post('email'),
			'address'      => $this->post('address'),
			'source'       => $this->post('source'),
			'workFlow'     => $this->post('workFlow'),
			'followTime'   => $this->post('followTime'),
			'poolId'       => $this->post('poolId') ?: self::defaulPoolId(),
			'region'       => $this->post('region'),
			'manager'      => $this->post('manager'),
			'collaborator' => $this->post('collaborator') && is_array($this->post('collaborator')) ? implode(',', array_unique($this->post('collaborator'))) : '',
			'text'         => $this->post('text'),
			'updateTime'   => $this->time,
		];
		$annotation = [
			'name'    => L('clue.editEdit.name'),
			'manager' => L('clue.editEdit.manager'),
		];
		$rules      = [
			'name'    => 'required',
			'manager' => 'required',
		];
		// 校验是否符合规则
		$vt     = new \verify();
		$result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
		if ($result === false) {
			$json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
			goto resp;
		}
		//判断
		if (!$this->power(self::page, "edit")) {
			$json['warn'] = L('clue.editEdit.power');
		} elseif (empty($field['tel']) && empty($field['landline'])) {
			$json['warn'] = L('clue.editEdit.telLandline');
		} elseif (!empty($field['tel']) && preg_match(checkTel, $field['tel']) == 0) {
			$json['warn'] = L('clue.editEdit.telError');
		} elseif (!empty($field['email']) && preg_match(checkEmail, $field['email']) == 0) {
			$json['warn'] = L('clue.editEdit.emailError');
		} elseif (!empty($field['qq']) && preg_match(checkInteger, $field['qq']) == 0) {
			$json['warn'] = L('clue.editEdit.qqError');
		} elseif (!empty($field['website']) && preg_match(checkUrl, $field['website']) == 0) {
			$json['warn'] = L('clue.editEdit.websiteError');
		} elseif (is_array($this->post('collaborator')) && in_array($field['manager'], $this->post('collaborator'))) {
			$json['warn'] = L('clue.editEdit.collaboratorError');
		} elseif (!empty($field['tel']) && static::total(array('table' => self::table, 'where' => "tel = '$field[tel]' and id !='$id'")) > 0) {
			$json['warn'] = L('clue.editEdit.telRepeat');
		} elseif (!empty($field['landline']) && static::total(array('table' => self::table, 'where' => " landline = '$field[landline]' and id !='$id'")) > 0) {
			$json['warn'] = L('clue.editEdit.landlineRepeat');
		} else {
			//查看范围
			$field['see'] = implode(',', array_unique(array_merge(explode(',', $field['collaborator']), [$field['manager']])));
            // 经纬度及地区处理
            if ($this->post('location')){
                $location = explode(',', $this->post('location'));
                $field['lat'] = $location[0];
                $field['lng'] = $location[1];
                if(empty($field['region'])) {
                    $region = componentClass::coordinateToAddr($field['lat'], $field['lng']);
                    if ($region['err_code'] == 0) {
                        $field['region'] = $region['data']['address_component']['province'] . '-' . $region['data']['address_component']['city'] . '-' . $region['data']['address_component']['district'];
                    }
                }
            }

			$where = " id = '$id' ";
			$info  = query(self::table, $where);
			if (!$info['id']) {
				$field        = array_merge($field, [
					'id'   => $id,
					'stid' => $this->control['stid'],
                    'coid'=>self::$coid,
					'time' => $this->time,
				]);
				$json['warn'] = static::insert(["table" => self::table, "field" => $field]);
			} else {
				$json['warn'] = static::update([
					"table" => self::table,
					"field" => $field,
					"where" => $where,
				]);
			}
			if (in_array($json['warn'], ["新增成功", "更新成功"])) {
				$tagsText = '';
				//添加标签
				$kehu_label_id = [];
				if (!empty($labelMxId) && is_array($labelMxId)) {
					foreach ($labelMxId as $tagsId) {
						$kehu_label  = query('kehu_label', "targetId = '$id' and tag_detail_id = '$tagsId'");
						$tags_detail = query('tag_detail', "id = '$tagsId'");
						$tags        = query('tag', "id = '$tags_detail[orderId]'");
						$tagsText    .= $tags_detail['name'] . ',';
						if (empty($kehu_label['id'])) {
							$mid             = self::getId();
							$kehu_label_id[] = $mid;
							static::insert(array(
								'table' => 'kehu_label',
								'field' => [
									'id'            => $mid,
                                    'coid'=>self::$coid,
									'targetId'      => $id,
									'tag_detail_id' => $tagsId,
									'tagId'         => $tags['id'],
									'type'          => 0,
									'time'          => $this->time,
								],
							));
						} else {
							$kehu_label_id[] = $kehu_label['id'];
						}
					}
				}
				//删除无效关联的标签
				delete(array('table' => 'kehu_label', 'where' => "id not in ('" . implode("','", $kehu_label_id) . "') and targetId = '$id'"));
				update(array('table' => self::table, 'field' => ['tags' => $tagsText], 'where' => "id = '$id'"));
				//添加日志
				$type = mb_substr($json['warn'], 0, 2, 'utf-8');
				$text = str_replace(['{{staffName}}', '{{type}}', '{{id}}'], [$this->control['name'], $type, $id], L('clue.editEdit.log'));
				$this->logWrite($id, $type);
				$this->logText(["type" => self::page, "text" => $text]);
				//返回
				$_SESSION['warn'] = $json['warn'];
				$json['warn']     = 2;
				$json['href']     = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&id=" . $id;
			}
		}

		resp:
		return json_encode($json, 320);
	}

	/*详情页*/
	public function detail(): string
	{
		$info = query(self::table, " id = '{$this->get('id')}'");
		if (empty($info['id'])) {
			$html = L('clue.detail.empty');
		} else {
			//菜单
			$data   = array(
				"id"    => $info['id'],
				"title" => L('clue.detail.detail'),
				'menu'  => [
					'edit'   => L('clue.detail.info'),
					'file'   => array("name" => L('clue.detail.file'), "cla" => "file", "fun" => "clueFile"),
					'follow' => array("name" => L('clue.detail.follow'), "cla" => "follow", "fun" => "clueRecord"),
					'log'    => L('clue.detail.operateLog'),
				],
			);
			$pool   = query('pool', "id = '$info[poolId]'");
			$button = [];
			if ($this->power(self::page, "edit") && self::$stid == $info['manager']) {
				//按钮
				$button[] = [
					"name"  => L('clue.detail.edit'),
                    "type" => "弹出层",
                    "cla" => $this->get('cla'),
                    "fun" => "edit",
                    "post" => ["id" => $info['id']],
					'style' => 'li-btn-blue-bg',
				];
				//按钮
				$button[] = [
					"name" => L('clue.detail.client'),
					"type" => "弹出层",
					"cla"  => $this->get('cla'),
					"fun"  => "operate",
					"post" => ["act" => 'client', "id" => $info['id']],
				];
				//按钮
				$button[] = [
					"name"  => L('clue.detail.transfer'),
					"type"  => "点击事件",
					"title" => L('clue.detail.transfer'),
					'fun'   => "layer('" . self::page . "','transfer',{id:'" . $info['id'] . "'})",
				];
				//按钮
				$button[] = [
					"name"  => L('clue.detail.pool'),
					"type"  => "点击事件",
					"title" => L('clue.detail.pool'),
					'fun'   => "layer('" . self::page . "','pool',{id:'" . $info['id'] . "'})",
				];
			}
			if ($this->power(self::page, "del") and self::$stid == $info['manager']) {
				//按钮
				$button[] = [
					"name" => L('clue.detail.del'),
					"type" => "弹出层",
					"cla"  => $this->get('cla'),
					"fun"  => "operate",
					"post" => ["act" => 'del', "id" => $info['id']],
				];
			}
			/******标签*********/
			$tags       = '';
			$kehu_label = find(array('table' => 'kehu_label', 'where' => "targetId = '$info[id]' order by list asc"));
			foreach ($kehu_label['array'] as $array) {
				$tag_detail = query('tag_detail', "id = '$array[tag_detail_id]'");
				$tags       .= "<span class='background-color-gray' style='margin-right: 5px'>{$tag_detail['name']}</span>";
			}
			//生成表单
            $data['button'] = $this->tableShowButton($button);
			$data['html'] = $this->tableShow(array(
				"详细信息" => array(
					array(
						L('clue.detail.name')        => $info['name'],
						L('clue.detail.companyName') => $info['companyName'],
						L('clue.detail.department')  => $info['department'],
                        L('clue.detail.job')      => $info['job'],
					),
					array(
						L('clue.detail.birthDay') => text(array('name' => 'birthDay', 'title' => L('clue.detail.birthDayWrite'), 'class' => 'display-hidden', 'laydate' => ['done' => "function(value, date, endDate){setVal(value)}"], 'value' => self::null($info['birthDay'], false))),
					),
				),
				L('clue.detail.contactInfo') => array(
					array(
						L('clue.detail.tel')      => $info['tel'],
						L('clue.detail.landline') => $info['landline'],
						L('clue.detail.weChat')   => $info['weChat'],
                        L('clue.detail.qq')      => $info['qq'],
					),
					array(
						L('clue.detail.website') => $info['website'],
						L('clue.detail.email')   => $info['email'],
					),
				),
				L('clue.detail.manageInfo')  => array(
					array(
						L('clue.detail.source') => $info['source'],
						L('clue.detail.tags')   => $tags,
						L('clue.detail.workFlow')   => $info['workFlow'],
						L('clue.detail.followTime') => $info['followTime'],
					),
					array(
						L('clue.detail.belongPool')   => self::setBackGroundColorGray($pool['name']),
						L('clue.detail.manager')      => self::findStaff($info['manager']),
						L('clue.detail.collaborator') => self::showMember($info['collaborator']),
					),
				),
				L('clue.detail.sys')         => array(
					array(
						L('clue.detail.stid')       => self::findStaff($info['stid']) . hidden(array('name' => 'id', 'value' => $info['id'])),
						L('clue.detail.time')       => $info['time'],
						L('clue.detail.updateTime') => $info['updateTime'],
					),
				),
			));
			//生成页面
			$data['html'] .= <<<efo
<style>
.display-hidden{border: none}
.display-hidden:focus{border: 1px solid #d7d7d7;line-height: 16px;
    height: 16px;
    width: 200px;
    padding: 6px;
    border-radius: 4px;}
</style>
<script>
function setVal(value){
      let id = $("[name='id']").val();
     $.post(root+'control/adIndex.html?cla={$this->get('cla')}&fun=setVal',{id:id,value:value},function(res) {
                if(res.warn !== 1){
                   warn(res.warn)
                }
            },'json')
}
</script>
efo;

			$html = $this->tab($data);
		}
		//返回
		return $html;
	}

	/**
	 * 填写生日
	 *
	 * @return bool|string
	 */
	public function setVal()
	{
		$id    = $this->post('id');
		$value = $this->post('value');
		$info  = query(self::table, " id = '$id' ");
		if (!$this->power(self::page, 'edit')) {
			$json['warn'] = L('clue.setVal.power');
		} elseif (empty($info['id'])) {
			$json['warn'] = L('clue.setVal.empty');
		} else {
			$json['warn'] = update([
				'table' => self::table,
				'field' => [
					'birthDay' => $value,
				],
				'where' => " id = '$id' ",
			]);
			if ($json['warn'] == '更新成功') {
				$json['warn'] = 1;
				$this->logWrite($id, '更新');
			}
		}
		return json_encode($json, 320);
	}


	/**
	 * 展示姓名
	 *
	 * @param     $member
	 * @param int $style
	 * @return string
	 */
	public static function showMember($member, $style = 1): string
	{
		$result = '';
		if ($member) {
			$memberArr = !is_array($member) ? explode(',', $member) : $member;
			foreach ($memberArr as $stid) {
				$name = self::findStaff($stid);
				if ($style == 1) {
					$result .= self::setBackGroundColorGray($name);
				} else {
					$result .= ',' . $name;
				}
			}
		}
		if ($style !== 1 && $result) {
			$result = ltrim($result, ',');
		}
		return $result;
	}

	/**
	 * 添加背景颜色
	 *
	 * @param $text
	 * @return string
	 */
	public static function setBackGroundColorGray($text): string
	{
		return $text ? "<span class='background-color-gray'>{$text}</span>" : '';
	}


	/**
	 * 下载模板
	 */
	public function downloadModel()
	{
        $templateId = $this->get('templateId');
		if (!$this->power(self::page, 'import')) {
			$_SESSION['warn'] = L('clue.downloadModel.power');
        }   else {
            $exampleData[] = [
				'邱女士', '重庆雨木科技', '总经办', '行政', '13000000000', '44340001', '1995-01-01', 'wechat001', '10001', 'www.yumukeji.com', '001@yumukeji.com',
				'重庆市南岸区国际社区', '官网', '初次联系', '2021-01-01 00:00:00', '默认线索池(不填也为默认线索池)', '张三', 'YM202111220001', '李四,王五', 'YM202111220002,YM202111220003',
				'(样例数据，导入时请删除本条数据)',
			];
            $excel    = $this->excelHead();
            $fileName = self::title.'导入模板-'.importTemplateClass::getName($templateId).'.xlsx';
            $filePath = $excel->fileName($fileName, 'sheet1');
            $format = new \Vtiful\Kernel\Format($filePath->getHandle());
            $templateField = importTemplateClass::templateField(self::page, 'importFieldInit', id:$templateId);
            $index         = 0;
            foreach ($templateField as $k => $array) {
                if ($array['display']){
                    $backgroundStyle=null;
                    if (importTemplateClass::getIsMustValue($this->importFieldInit(), $array['columnName'])){
                        //必填项判断
                        $backgroundStyle  = $format->background(
                            0xFFC04B
                        )->toResource();
                    }
                    $filePath->insertText(0, $index, $array['aliasName'],'',$backgroundStyle);
                    foreach ($exampleData as $y=>$example){
                        $exampleVal = match ($array['columnName']){
                            '姓名'=>$example[0],
                            '公司名称'=>$example[1],
                            '部门'=>$example[2],
                            '职务'=>$example[3],
                            '手机'=>$example[4],
                            '电话'=>$example[5],
                            '出生年月'=>$example[6],
                            '微信号'=>$example[7],
                            'QQ号'=>$example[8],
                            '网址'=>$example[9],
                            '邮箱'=>$example[10],
                            '地址'=>$example[11],
                            '线索来源'=>$example[12],
                            '跟进状态'=>$example[13],
                            '下次跟进时间'=>$example[14],
                            '所属线索池'=>$example[15],
                            '负责人'=>$example[16],
                            '负责人编号'=>$example[17],
                            '协作人'=>$example[18],
                            '协作人编号'=>$example[19],
                            '备注'=>$example[20],
                            default=>'',
                        };
                        $filePath->insertText($y+1, $index, $exampleVal);
                    }
                    $index++;
                }
            }
			$text   = str_replace(['{{staffName}}'], [$this->control['name']], L('clue.downloadModel.log'));
			$this->logText(["type" => self::page, "text" => $text]);
            $this->excelOutPut($filePath,$fileName);
			exit(0);
		}
		header("Location:" . getenv("HTTP_REFERER"));
	}


	/*数据导入*/
	public function importData()
	{
        $templateId = $this->post('templateId');
		if (!$this->power(self::page, 'import')) {
			$json['warn'] = L('clue.importData.power');
        } else {
			 $fomatArray = [];//导入数据格式同一为TYPE_STRING
            foreach ($this->importFieldInit() as $value){
                $fomatArray[] = \Vtiful\Kernel\Excel::TYPE_STRING;
            }
            $data = $this->importHead(format: $fomatArray);
			$x    = 0;
			$text = '';
            $headArray = [];
            $row_list=0;
			foreach ($data as $i => $row) {
                $row_list++;
                if ($i==0){
                    $templateField = importTemplateClass::templateField(self::page, 'importFieldInit', id:$templateId);
                    $headArray = importTemplateClass::combinHead($templateField,$row);
                }
				if ($i > 0) {
                    $rowData = formSubArray($row);
                    //只接收模板中选中的字段的值
                    $cell = [];
                    foreach ($headArray as $index=>$headName){
                        $cell[$headName] = $rowData[$index]??'';
                    }
                    //初始化未被模板需要的字段的值
                    foreach ($this->importFieldInit() as $value){
                        $cell[$value['columnName']] = $cell[$value['columnName']]??'';
                    }
					$manager = query("staff", "orderNo = '$cell[负责人编号]'");
					$partner = explode(',', $cell['协作人编号']);

					$collaborator = [];
					foreach ($partner as $stid) {
						$staff          = query('staff', "orderNo = '$stid' and orderNo !=''");
                        if ($cell['协作人编号'] && $staff['stid']){
                            $collaborator[] = $staff['stid'];
                        }
					}

					$pool = query('pool', "name = '$cell[所属线索池]' and type = '线索池' and coid = '".self::$coid."'");

					$field      = [
						'id'           => self::getId(),
                        'coid'=>self::$coid,
						'name'         => $cell['姓名'],
						'companyName'  => $cell['公司姓名'] ?: $cell['姓名'],
						'department'   => $cell['部门'],
						'job'          => $cell['职务'],
						'tel'          => $cell['手机'],
						'landline'     => $cell['电话'],
						'birthDay'     => $cell['出生年月'],
						'weChat'       => $cell['微信号'],
						'qq'           => $cell['QQ号'],
						'website'      => $cell['网址'],
						'email'        => $cell['邮箱'],
						'address'      => $cell['地址'],
						'source'       => $cell['线索来源'],
						'workFlow'     => $cell['跟进状态'],
						'followTime'   => $cell['下次跟进时间'],
						'poolId'       => $pool['id'] ?: self::defaulPoolId(),
						'manager'      =>  $cell['负责人编号']?$manager['stid']:'',
						'stid'         => self::$stid,
						'collaborator' => implode(',', array_filter(array_unique($collaborator))),
						'text'         => $cell['备注'],
						'updateTime'   => $this->time,
					];
					$annotation = [
						'name'    => L('clue.importData.name'),
						'manager' => L('clue.importData.manager'),
					];
					$rules      = [
						'name'    => 'required',
						'manager' => 'required',
					];
					// 校验是否符合规则
					$vt     = new \verify();
					$result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
					if (!empty($cell[16]) && !$manager['stid']) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.empty'));
					} elseif ($result === false) {
						$text .= "\n" . str_replace(['{{i}}'], [$row_list], L('clue.importData.validateError')) . $vt->getErrs()[0];
					} elseif (empty($field['tel']) && empty($field['landline'])) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.telLandline'));
					} elseif (!empty($field['tel']) && preg_match(checkTel, $field['tel']) == 0) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.telError'));
					} elseif (!empty($field['email']) && preg_match(checkEmail, $field['email']) == 0) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.emailError'));
					} elseif (!empty($field['qq']) && preg_match(checkInteger, $field['qq']) == 0) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.qqError'));
					} elseif (!empty($field['website']) && preg_match(checkUrl, $field['website']) == 0) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.websiteError'));
					} elseif (static::total(array('table' => self::table, 'where' => "name = '$field[name]' and tel = '$field[tel]'")) > 0) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.nameRepeat'));
					} elseif (!empty($field['tel']) && static::total(array('table' => self::table, 'where' => "tel = '$field[tel]'")) > 0) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.telRepeat'));
					} elseif (!empty($field['landline']) && static::total(array('table' => self::table, 'where' => " landline = '$field[landline]'")) > 0) {
						$text .= str_replace(['{{i}}'], [$row_list], L('clue.importData.landlineRepeat'));
					} else {
						//查看范围
						$field['see'] = implode(',', array_filter(array_unique(array_merge(explode(',', $field['collaborator']), [$field['manager']]))));
						if (!empty($field['address'])) {
							//解析地址信息 得到经纬度和省市区
							$locationRes = componentClass::addrToCoordinate($field['address']);
							if ($locationRes['err_code'] == 0) {
								$field['lat'] = $locationRes['data']['location']['lat'];
								$field['lng'] = $locationRes['data']['location']['lng'];
								$region       = componentClass::coordinateToAddr($field['lat'], $field['lng']);
								if ($region['err_code'] == 0) {
									$field['region'] = $region['data']['address_component']['province'] . '-' . $region['data']['address_component']['city'] . '-' . $region['data']['address_component']['district'];
								}
							}
						}
						$warn = insert(["table" => self::table, "field" => $field]);
						if (in_array($warn, ["新增成功", "更新成功"])) {
							$x++;
							$text .=  "第{$row_list}行导入成功<br>";
						} else {
							$text .= "第{$row_list}行导入失败：{$warn}<br>";
						}
					}
				}
			}
            $total = count($data)-1;
            $json['data'] = [
                'text'=>$text,
                'title'=>"您导入了{$total}条数据，成功{$x}条，失败".($total-$x)."条",
            ];
			$text = str_replace(['{{staffName}}', '{{fileName}}'], [$this->control['name'], $_FILES['file']['name']], L('clue.importData.log')) . $text;
			$this->logText(["type" => self::page, "text" => $text]);
            $json['warn'] = 2;
        }
        return json_encode($json,320);
	}

	/**
	 * 导出
	 */
	public function exportData()
	{
        $templateId = $this->get('templateId');
        $checkedId = $this->get('checkedId')?explode(',',$this->get('checkedId')):[];
		if (!$this->power(self::page, 'export')) {
			$_SESSION['warn'] = L('clue.exportData.power');
        }  else {
			$data              = [];
            /***********标题**********/
            $title =[];
            $tempFieldAll = importTemplateClass::templateField(self::page, 'exportFieldInit', id:$templateId);
            foreach ($tempFieldAll as $array) {
                if ($array['display']){
                    $title[] = $array['aliasName'];
                }
            }
            //判断是否选中导出
            if (!self::is_null_array($checkedId)){
                $result = find(array(
                    "table" => self::table,
                    "where" => "id in ('".implode("','", $checkedId)."') order by time desc",
                ))['array'];
            }else{
                $sql   = $_SESSION[self::page]['sql'];
                $result   = sqlFind($sql);
            }
            //导出数据生成
            foreach ($result as $array){
                $column = [];
                $pool       = query('pool', " id = '$array[poolId]'");
                $tags       = '';
                $kehu_label = find(array('table' => 'kehu_label', 'where' => "targetId = '$array[id]' order by list asc"));
                foreach ($kehu_label['array'] as $val) {
                    $tag_detail = query('tag_detail', "id = '$val[tag_detail_id]'");
                    $tags       .= $tag_detail['name'] . ',';
                }
                foreach ($tempFieldAll as $templateField){
                    if ($templateField['display']){
                        $column[] = match ($templateField['columnName']){
                            '姓名'=>$array['name'],
                            '公司名称'=>$array['companyName'],
                            '部门'=>$array['department'],
                            '职务'=>$array['job'],
                            '出生年月'=>$array['birthDay'],
                            '手机'=>$array['tel'],
                            '电话'=>$array['landline'],
                            '微信号'=>$array['weChat'],
                            'QQ号'=>$array['qq'],
                            '网址'=>$array['website'],
                            '邮箱'=>$array['email'],
                            '地址'=>$array['address'],
                            '线索来源'=>$array['source'],
                            '跟进状态'=>$array['workFlow'],
                            '下次跟进时间'=>$array['followTime'],
                            '所属线索池'=>$pool['name'],
                            '标签'=>$tags,
                            '负责人'=>self::findStaff($array['manager']),
                            '协作人'=>self::showMember($array['collaborator'], 2),
                            '备注'=>$array['text'],
                            '创建人'=>self::findStaff($array['stid']),
                            '更新时间'=>$array['updateTime'],
                            '创建时间'=>$array['time'],
                            default=>'',
                        };
                    }
                }
                $data[] = $column;
            }
			$text = str_replace(['{{staffName}}'], [$this->control['name']], L('clue.exportData.log'));
			$this->logText(["type" => self::page, "text" => $text]);
			$this->excelOut($title, $data, L('clue.exportData.fileName') . ".xlsx");
            exit(0);
		}
		header("Location:" . getenv("HTTP_REFERER"));
	}

	// 操作中转
	public function operate()
	{
		$act  = $this->post('act') ?? '';
		$pwd  = false; // 需要密码
		$form = $word = $power = '';
		switch ($act) {
			case 'client':
				//转成客户
				$act      = 'edit';
				$msg      = L('clue.operate.edit');
				$title    = L('clue.operate.editTitle');
				$function = 'client';
				$form     = self::page . 'OperateForm, listForm';
				$word     = true;

				break;
			default:
				$act      = 'del';
				$msg      = L('clue.operate.del');
				$title    = self::page . 'Delete';
				$function = 'delete';
				$form     = self::page . 'OperateForm, listForm';
				$power    = '';
				break;
		}
		if (!$this->power(self::page, $act)) {
			$_SESSION['warn'] = str_replace(['{{msg}}'], [$msg], L('clue.operate.warn'));
			$json             = [
				'warn' => 2,
				'href' => root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=home',
			];
		} else {
			return $this->confirm([
				'title'    => $title,
				'function' => $function,
				'form'     => $form,
				'power'    => $power,
				'pwd'      => $pwd,
				'word'     => $word,
			]);
		}

		resp:
		return json_encode($json, 320);
	}


	/**
	 * 删除
	 *
	 * @return bool|string
	 */
	public function delete()
	{
		$array = $this->post('listId') ?? $this->post('id');
		if (!$this->power(self::page, "del")) {
			$json['warn'] = L('clue.delete.power');
		} elseif (empty($array)) {
			$json['warn'] = L('clue.delete.noChoice');
		} else {
			$text  = "";
			$x     = 0;
			$array = is_array($array) ? $array : [$array];
			foreach ($array as $id) {
				$info = query(self::table, " id = '$id' ");
				if ($info['manager'] != self::$stid) {
					//返回
					$warn = L('clue.delete.fail');
				} else {
					$result = find(array('table' => 'file', 'where' => "targetId = '$id'"));
					foreach ($result['array'] as $file) {
						fileDelete($file['src']);
					}
					//删除附件
					delete(array("table" => "file", "where" => " targetId = '$id' "));
					//删除标签
					delete(array("table" => "kehu_label", "where" => " targetId = '$id' "));
					//删除跟进记录
					delete(array("table" => "follow", "where" => " targetId = '$id' "));
					//删除操作日志
					delete(array("table" => "clue_log", "where" => " orderId = '$id' "));
					//最后删除基本参数
					delete(array("table" => self::table, "where" => " id = '$id' "));
					//返回
					$warn = L('clue.delete.success');
					$x++;
				}
				$text .= str_replace(['{{id}}'], [$info['id']], L('clue.delete.text')) . $warn . "。<br>";
			}
			//添加日志
			$text = str_replace(['{{staffName}}'], [$this->control['name']], L('clue.delete.log')) . "<br>" . $text;
			$this->logText(array("type" => self::page, "text" => $text));
			$_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('clue.delete.warn'));
			$json['warn']     = 2;
			$json['href']     = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=home";
		}
		return json_encode($json, 320);
	}

    /*列表页-查询条件*/
    public function logOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    L('clue.log.recordDate') => text(array("name" => "recordDate", 'laydate' => ['type' => 'date', 'range' => '~'])) .
                        hidden(array('name' => 'id', 'value' => $this->get('id')))
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

	/**
	 * 操作记录
	 */
	public function log()
	{
		$html  = $this->logOptions(false);
        $button = "";
		$json['html'] = $this->search($html, layout: 'pop', toolButton: $button);
		return json_encode($json, 320);
	}

	/**
	 * 操作记录
	 *
	 * @return bool|string
	 */
	public function logSearch()
	{
		$id    = $this->post('id');
		$where = " and orderId = '$id'";
		if ($this->post('recordDate')) {
			$timeArr = explode(' ~ ', $this->post('recordDate'));
			$where   .= " and date(time) >='{$timeArr[0]}' and  date(time) <='{$timeArr[1]}'";
		}

		$page = $this->page([
			"table" => "clue_log",
			"where" => " {$where} ",
			"order" => "`time` desc",
		]);
		//获取表头
		$tr[] = ['{l.clue.logSearch.operateTime}', '{l.clue.logSearch.operator}', '{l.clue.logSearch.operateType}', '{l.clue.logSearch.remark}'];
		//获取记录
		foreach ($page['array'] as $array) {
			$tr[] = array(
				$array['time'],
				$array['staffName'],
				$array['type'],
				$array['text'],
			);
		}
		//控件
		$json['html'] = $page['hint'] . "<form name='topicForm'>" . space . $this->tableMany(array("tr" => $tr)) . "</form>" . $page['button'];
		return json_encode($json, 320);
	}

	/**
	 * 日志写入
	 */
	public function logWrite($id, $type, $text = '')
	{
		$info = query(self::table, " id = '$id'");
		insert(array(
			'table' => 'clue_log',
			'field' => [
				'id'        => self::getId(),
                'coid'=>self::$coid,
				'orderId'   => $id,
				'classify'  => '线索',
				'type'      => $type,
				'text'      => $text ?: $this->control['name'] . $type . '了线索【' . $info['name'] . '】',
				'staffName' => $this->control['name'],
				'stid'      => $this->control['stid'],
				'time'      => $this->time,
			],
		));
	}

    /**
     * 导入模板字段初始化
     * @return array[]
     */
    public function importFieldInit($classify=''): array
    {
        return match ($classify) {
            default=>  [
                [
                    'columnName'=>'姓名',
                    'aliasName'=>'姓名',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'公司名称',
                    'aliasName'=>'公司名称',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'部门',
                    'aliasName'=>'部门',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'职务',
                    'aliasName'=>'职务',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'手机',
                    'aliasName'=>'手机',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'电话',
                    'aliasName'=>'电话',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'出生年月',
                    'aliasName'=>'出生年月',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'微信号',
                    'aliasName'=>'微信号',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'QQ号',
                    'aliasName'=>'QQ号',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'网址',
                    'aliasName'=>'网址',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'邮箱',
                    'aliasName'=>'邮箱',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'地址',
                    'aliasName'=>'地址',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'线索来源',
                    'aliasName'=>'线索来源',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'跟进状态',
                    'aliasName'=>'跟进状态',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'下次跟进时间',
                    'aliasName'=>'下次跟进时间',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'所属线索池',
                    'aliasName'=>'所属线索池',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'负责人',
                    'aliasName'=>'负责人',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'负责人编号',
                    'aliasName'=>'负责人编号',
                    'isMust'=>true,
                ],
                [
                    'columnName'=>'协作人',
                    'aliasName'=>'协作人',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'协作人编号',
                    'aliasName'=>'协作人编号(多个用英文逗号隔开)',
                    'isMust'=>false,
                ],
                [
                    'columnName'=>'备注',
                    'aliasName'=>'备注',
                    'isMust'=>false,
                ],

            ]
        };
    }

    /**
     * 导出模板字段初始化
     * @return array[]
     */
    public function exportFieldInit($classify=''): array
    {
        return match ($classify) {
            default=>  [
                [
                    'columnName'=>'姓名',
                    'aliasName'=>'姓名',
                ],
                [
                    'columnName'=>'公司名称',
                    'aliasName'=>'公司名称',
                ],
                [
                    'columnName'=>'部门',
                    'aliasName'=>'部门',
                ],
                [
                    'columnName'=>'职务',
                    'aliasName'=>'职务',
                ],
                [
                    'columnName'=>'出生年月',
                    'aliasName'=>'出生年月',
                ],
                [
                    'columnName'=>'手机',
                    'aliasName'=>'手机',
                ],
                [
                    'columnName'=>'电话',
                    'aliasName'=>'电话',
                ],
                [
                    'columnName'=>'微信号',
                    'aliasName'=>'微信号',
                ],
                [
                    'columnName'=>'QQ号',
                    'aliasName'=>'QQ号',
                ],
                [
                    'columnName'=>'网址',
                    'aliasName'=>'网址',
                ],
                [
                    'columnName'=>'邮箱',
                    'aliasName'=>'邮箱',
                ],
                [
                    'columnName'=>'地址',
                    'aliasName'=>'地址',
                ],
                [
                    'columnName'=>'线索来源',
                    'aliasName'=>'线索来源',
                ],
                [
                    'columnName'=>'跟进状态',
                    'aliasName'=>'跟进状态',
                ],
                [
                    'columnName'=>'下次跟进时间',
                    'aliasName'=>'下次跟进时间',
                ],
                [
                    'columnName'=>'所属线索池',
                    'aliasName'=>'所属线索池',
                ],
                [
                    'columnName'=>'标签',
                    'aliasName'=>'标签',
                ],
                [
                    'columnName'=>'负责人',
                    'aliasName'=>'负责人',
                ],
                [
                    'columnName'=>'协作人',
                    'aliasName'=>'协作人',
                ],
                [
                    'columnName'=>'备注',
                    'aliasName'=>'备注',
                ],
                [
                    'columnName'=>'创建人',
                    'aliasName'=>'创建人',
                ],
                [
                    'columnName'=>'更新时间',
                    'aliasName'=>'更新时间',
                ],
                [
                    'columnName'=>'创建时间',
                    'aliasName'=>'创建时间',
                ],
            ]
        };
    }
}
